/*
 * temp.cpp
 *
 *  Created on: 2010.06.28
 *      Author: Tadas
 */

int main() {
	seed = time(NULL);

	long i, n1 = 1e7, n;
	double x, y, z;
	double sw, swx, swy, swz;
	double varw, varx, vary, varz;
	double w, xw, yw, zw;
	double den, vol, a, den2, volume;
	double v, vx, vy, vz, s;
	a = sqrt(2);
	den = 1;
	den2 = den * den;

	v = vx = vy = vz = volume = 0;
	sw = swx = swy = swz = 0.0;
	varw = varx = vary = varz = 0.0;
	
	vol = 48;
	
	n = 0;

	for (i = 0; i < n1; i++) {
		n++;
		x = 3 * randGe() + 1;
		y = 7 * randGe() - 3;
		s = (0.2 * a - 0.2) * randGe() + 0.2;
		z = log(5 * s) / 5;
		den = tank(z);
		//den = 1;
		den2 = den * den;
		if (func(x, y, z) <= 1) {
			sw += den;
			swx += x * den;
			swy += y * den;
			swz += z * den;

			varw += den2;
			varx += x * x * den2;
			vary += y * y * den2;
			varz += z * z * den2;
		}
	}
	n1 *= 2;

	w = sw / n * vol;
	xw = swx / sw;
	yw = swy / sw;
	zw = swz / sw;

	volume += w / den;

	v += w;
	vx += xw;
	vy += yw;
	vz += zw;

	//	printf("\nVidurkis:\n%.3f\t(%.3f ; %.3f ; %.3f)\n", v, vx, vy, vz);
	cout << "Mases c. x: " << vx << " y: " << vy << " z: " << vz << endl;
	//	printf("Turis: %.3f\n", volume/12);
	cout << "Turis: " << volume << endl;

	return 0;
}
